export function Padding(str: string, num: number, PaddingLeft: boolean = true, tchar: string = " "): string {
    if (str.length >= num) {
        return str;
    } else {
        let tn: number = num - str.length;
        let temstr: string = "";
        for (var index = 0; index < num - str.length; index++) {
            temstr = temstr + tchar;
        }
        temstr = temstr + str;
        return temstr;
    }
}
export function IsIP(obj: string): boolean {
    var re = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
    return re.test(obj);
}
export function IsInt(obj: string): boolean {
    var re = /^\d{1,8}$/;
    return re.test(obj);
}
export function IsNetPort(obj: string): boolean {
    var re = /^\d+$/;
    return re.test(obj);
}
export function IsMac(obj: string): boolean {
    var re = /[A-F\d]{2}:[A-F\d]{2}:[A-F\d]{2}:[A-F\d]{2}:[A-F\d]{2}:[A-F\d]{2}/;
    return re.test(obj);
}
export function IsHex(obj: string): boolean {
    obj = RemoveAllSpace(obj);
    if (obj.length % 2 == 0 && obj.length < 41) {
        var re = /^[0-9a-fA-F ]+$/;
        return re.test(obj);
    } else {
        return false;
    }

}
export function Trim(obj: string): string {
    return obj.replace(/^\s+|\s+$/gm, '');
}

export function IsURL(obj: string): boolean {
    var Expression = /http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
    return Expression.test(obj);

}
export function RemoveAllSpace(obj: string): string {
    return obj.replace(/\s+/g, "");
}
export function clone(obj) {
    var buf;
    if (obj instanceof Array) {
        buf = [];
        var i = obj.length;
        while (i--) {
            buf[i] = clone(obj[i]);
        }
        return buf;
    }
    else if (obj instanceof Object) {
        buf = {};
        for (var k in obj) {
            buf[k] = clone(obj[k]);
        }
        return buf;
    }
    else {
        return obj;
    }
}